package com.zjl.quartz.test001;

import com.zjl.quartz.test001.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Demo {
    public static final String COUNT = "count";

    //这个属性如不是static,那么每次都要实例这个任务类,始终打印为: 1
    private static int num = 1;

    public static void main(String[] args) throws SchedulerException {
        SchedulerFactory schedulerfactory = new StdSchedulerFactory();
//        Scheduler scheduler = schedulerfactory.getScheduler();
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.start();
        JobDetail job = JobBuilder.newJob(HelloJob.class).withIdentity("jobName", "jobGroupName")
                .usingJobData(COUNT,num).build();
        // 各种builder 的基本使用
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().repeatForever().withIntervalInSeconds(3);
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("*/3 * * * * ?");
        CalendarIntervalScheduleBuilder calendarIntervalScheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withInterval(3, DateBuilder.IntervalUnit.SECOND);
        DailyTimeIntervalScheduleBuilder dailyTimeIntervalScheduleBuilder = DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule().withIntervalInSeconds(3);

        Trigger trigger =  TriggerBuilder.newTrigger().withIdentity("jobName", "jobGroupName")
                .withSchedule(dailyTimeIntervalScheduleBuilder)
                .startNow().build();
        scheduler.scheduleJob(job, trigger);
    }

}
